/*
 * Created on May 26, 2011
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.timber.util;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.Vector;

/**
 * @author joju.varghese
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ItemManger {
	
	
	  public static String insertItem(IteamBean iteamBean)
	  {
	    SLProcDescriptor procParams = new SLProcDescriptor("common..p_InsItem");
	    try {
	    	procParams.addProcP(new Integer(0));
	    	procParams.addProcP("P");
	    	procParams.addProcP(iteamBean.getItemCode());
	    	procParams.addProcP(iteamBean.getItemName());
	    	procParams.addProcP(iteamBean.getItemClass());
	    	procParams.addProcP(iteamBean.getLocation());
	    	procParams.addProcP(iteamBean.getLotNumber());
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getLength()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getWidth()));
	    	procParams.addProcP(iteamBean.getMeasurement());
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getQuantity()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getUnits()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getPurchasePrice()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getSalesPrice()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getProfitMargin()));
	    	procParams.addProcP(iteamBean.getPurchasedFrom());
	    	procParams.addProcP(iteamBean.getPurchasedDate());
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getTax()));
	    	procParams.addProcP(Global.getComapnayName());
	    	String sqlStr = procParams.getProcName() + procParams.getProcParams();
	    	Statement st = Global.getDBConnection().createStatement();
	    	Util.log( "ItemManger.updateCustomer()", sqlStr );
	    	System.out.println("[Item ] started insert ");
	    	st.execute( sqlStr );
	    	System.out.println("[Item ] end insert ");
	    	st.close();
	    }
	    catch( Exception ex )
		{
	    	
	    	System.out.println("[Item ] cannot insert ");
		}
	    
	    
	    return "Succes";
	  }

	  
	  public static Vector searchItem(IteamBean iteamBean)
	  {
	  	InventoryMgr inventoryMgr= new InventoryMgr();
	  	Vector v= new Vector();
	    try {
	    	v= inventoryMgr.getInventoryDetails(iteamBean);
	    }
	    catch( Exception ex )
		{
	    	
	    	System.out.println("[Item ] cannot Search ");
		}
	    
	    return v;
	  }

	  
	  public static String updateItem(IteamBean iteamBean)
	  {
	    SLProcDescriptor procParams = new SLProcDescriptor("common..p_UpdItem");
	    try {
	    	procParams.addProcP(iteamBean.getItemCode());
	    	procParams.addProcP(iteamBean.getItemName());
	    	procParams.addProcP(iteamBean.getItemClass());
	    	procParams.addProcP(iteamBean.getLocation());
	    	procParams.addProcP(iteamBean.getLotNumber());
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getLength()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getWidth()));
	    	procParams.addProcP(iteamBean.getMeasurement());
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getQuantity()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getPurchasePrice()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getSalesPrice()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getProfitMargin()));
	    	procParams.addProcP(iteamBean.getPurchasedFrom());
	    	procParams.addProcP(new Date( iteamBean.getPurchasedDate()));
	    	procParams.addProcP(Global.roundThreeDecimals(iteamBean.getTax()));
	    	procParams.addProcP("CMV");
	    	String sqlStr = procParams.getProcName() + procParams.getProcParams();
	    	Statement st = Global.getDBConnection().createStatement();
	    	Util.log( "ItemManger.updateItem()", sqlStr );
	    	System.out.println("[Item ] started Update ");
	    	st.execute( sqlStr );
	    	System.out.println("[Item ] end Update ");
	    	st.close();
	    }
	    catch( Exception ex )
		{
	    	
	    	System.out.println("[Item ] cannot Update ");
		}
	    
	    
	    return "Succes";
	  }

	  
	  public static String deleteItem(String itemCode)
	  {
	    SLProcDescriptor procParams = new SLProcDescriptor("common..p_DelItem ");
	    try {
	    	procParams.addProcP(itemCode);
	    	String sqlStr = procParams.getProcName() + procParams.getProcParams();
	    	Statement st = Global.getDBConnection().createStatement();
	    	Util.log( "deleteItem()", sqlStr );
	    	Util.log( "[Item ] started delete ");
	    	st.execute( sqlStr );
	    	Util.log( "[Item ] end delete ");
	    	st.close();
	    }
	    catch( Exception ex )
		{
	    	
	    	System.out.println("[Item ] cannot Delete ");
		}
	    
	    
	    return "Succes";
	  }
	  


}
